package com.cx330;

public class example90_01 {
    public static void main(String[] args) {
        Vehicle01 v1 = VehicleFactory01.getVehicle("Bike");
        v1.drive();
        Vehicle01 v2 = VehicleFactory01.getVehicle("Electromobile");
        v2.drive();
        Vehicle01 v3 = VehicleFactory01.getVehicle("Car");
        v3.drive();
    }
}

abstract class Vehicle01 { // 抽象产品父类
    public abstract void drive();
}

class Bike01 extends Vehicle01 {

    @Override
    public void drive() {
        System.out.println("骑自行车锻炼身体！");
    }
}

class Electromobile01 extends Vehicle01 {

    @Override
    public void drive() {
        System.out.println("骑电动车送外卖！");
    }
}

class Car01 extends Vehicle01 {

    @Override
    public void drive() {
        System.out.println("开车去上班！");
    }
}

class VehicleFactory01 {
    public static Vehicle01 getVehicle(String type) {
        switch (type) {
            case "Bike":
                return new Bike01();
            case "Electromobile":
                return new Electromobile01();
            case "Car":
                return new Car01();
        }
        return null;
    }
}